<?php
# !!!!!!!!!! DON'T MAKE ANY CHANGE IF YOU DON'T KNOW WHAT YOU'RE DOING !!!!!!!!!!
// --------------------------------------------------------------------------------------------------------------
// File Name              :	search.php
// Last Modification Time :	2008-02-01 24:00
// Last Modified by       :	turker (turker.biz@gmail.com)
// list of modifications  :
//
//	- 2008-02-01 turker
//		* 24:00 file created.
//
// --------------------------------------------------------------------------------------------------------------
if (eregi("search.php",$_SERVER['PHP_SELF'])) {
	header ("Location:../index.php");
	exit;
}
?>
<!--div:icerik -->
    <div id="icerik">
    <p>
<?php
$search=@trim($_GET['search']);
if (!empty($search)) {
  echo $_LANG['search']['searched'].': '.$prep->html($search);
  $search_term=$mysql->escape($search);
  $q=$mysql->query("SELECT id FROM $ITEMS_TABLE WHERE MATCH (item,summary,info) AGAINST ('$search_term' IN BOOLEAN MODE)");
  if ($mysql->numRows($q)>0) {
    $ids=array();
    while ($read=$mysql->fetch($q)) {
      $ids[]=@"$ITEMS_TABLE.id='".$read['id']."'";
    }
    $ids=implode(' or ',$ids);

    /*
    $active="and $EXCHANGES_TABLE.active='1' and $ITEMS_TABLE.active='1'";
    if (isAdmin()) $active='';
    $sql="select distinct $ITEMS_TABLE.id,$ITEMS_TABLE.*,$EXCHANGES_TABLE.name as ename,$EXCHANGES_TABLE.exchange,$ITEM_PRICES_TABLE.price,";
    $sql.="$ITEM_PRICES_TABLE.info as pinfo,$ITEM_PRICES_TABLE.campaign,$ITEM_PRICES_TABLE.campaign_price from $ITEMS_TABLE,$ITEM_CATS_TABLE,";
    $sql.="$ITEM_PRICES_TABLE,$EXCHANGES_TABLE where $ITEM_CATS_TABLE.item_id=$ITEMS_TABLE.id and ($ids) and ";
    $sql.="$ITEM_PRICES_TABLE.item_id=$ITEMS_TABLE.id and $ITEM_PRICES_TABLE.exchange_id=$EXCHANGES_TABLE.id and $ITEMS_TABLE.lang='$SITE_DEF_LANG' ";
    $sql.="$active group by $ITEM_PRICES_TABLE.item_id order by $ITEMS_TABLE.`order` asc";
    */
    $sql="select
        it.*,
        ip.price, ip.info as p_info, ip.campaign, ip.campaign_price, ip.active as p_active,
        ex.name as ex_name, ex.exchange, ex.active as e_active
        from $ITEMS_TABLE as it
        left join $ITEM_PRICES_TABLE as ip on it.id=ip.item_id
        left join $EXCHANGES_TABLE as ex on ex.id=ip.exchange_id
        where ($ids) and it.lang='$SITE_DEF_LANG'
        group by it.id order by it.`order` asc";
    $q=$mysql->query($sql);

    $i=0;
    echo '<table cellpadding="5" cellspacing="5" width="100%" id="itemslist">';
    echo '<tr>';
    while ($read=$mysql->fetch($q)) {
      $id=$item['id']; #*
      $title=$prep->html($item['item']); # urun adı*
      $summary=$prep->html($item['summary']); # urun özeti*
      $name=$item['name']; # urun permalink*
      $new=$item['new']; # yeni urun*
      $show_price=$item['show_price']; # fiyat goster*
      $item_active=$item['active']; # ürün aktif
      $image=$item['image']; # urun foto*
      $price=$item['price']; # fiyat*
      $info=$prep->html($item['p_info']); # fiyat açıklaması*
      $campaign=$item['campaign']; # kampanya*
      $campaign_price=$item['campaign_price']; # kampanya fiyatı*
      $item_price_active=$item['p_active']; # fiyat aktif *
      $ename=$prep->html($item['ex_name']); # kur adı*
      $exchange=$item['exchange']; # kur *
      $e_active=$item['e_active']; # kur aktif *

      // prepare item details
      $price="$price $ename +KDV";
      if (empty($image)||!file_exists('img/'.$image)) $image='template/img/noimg.png';
      else $image='img/'.$image;
      if ($new) $new='<img src="template/img/yeni.gif" />'; else $new='';
      if ($campaign_price>0&&$campaign) {
        $campaign='<img src="template/img/kampanya.gif" /><br />';
        $price="<s>$price</s> $campaign_price $ename +KDV";
      }
      else $campaign='';

      $item_link='<a href="index.php?page=item&id='.$id.'">'.$title.'</a>';
      if ($SITE_SEO) $item_link='<a href="'.$SITE_URL.'/item/'.$name.'">'.$title.'</a>';
      // -------------

      if (isAdmin()) {
        $show_price=1;
      }
      elseif (isLogged()) {
        if(!empty($item['price'])) {
          if ($show_price) {
            if ($item_price_active!='1'||$e_active!='1') $price=$_LANG['brands']['oostock'];
          }
          else $price=$_LANG['brands']['aprice'];
        }
        else $item_active=0;
      }
      else {
        if(!empty($item['price'])) {
          if ($SHOW_ITEM_PRICE==0) {
            $price='';
            $campaign='';
          }
          else {
            if ($show_price) {
              if ($item_price_active!='1'||$e_active!='1') $price=$_LANG['brands']['oostock'];
            }
            else $price=$_LANG['brands']['aprice'];
          }
        }
        else $item_active=0;
      }
      // -------------

      if (isAdmin()||$item_active=='1') {
        if (isAdmin()&&$item_active=='1') $item_active='<img src="template/img/active.gif" title="Ürün Aktif" />';
        elseif (isAdmin()&&$item_active=='0') $item_active='<img src="template/img/notactive.gif" title="Ürün Aktif Değil" />';
        else $item_active='';
        $price=trim($price);
        if ($price=='+KDV') $price=$_LANG['brands']['nhprice'];

        echo <<<html
        <td id="item-$id" class="item" width="50%">$new $item_link $item_active<br />
        <img src="$image" align="left" class="item-img" title="$title" />$summary<br /><br />
        $info<br />$campaign $price<br />
        </td>
html;
        if ($i%$ITEM_DISPLAY_COLUMN!=0) echo '</tr><tr>';
        $i++;
      }
    } // while

    echo '</tr></table>';
  } // if
  else echo '<br />'.$_LANG['search']['error2'];
}
else echo $_LANG['search']['error1'];
?>
</p>
    </div>
<!--//div:icerik -->